<template>
  <div class="container">
    <el-dialog
      title="题目审核"
      :visible="showCheckDialog"
      @close="btnCancel"
      width="30%"
    >
      <!-- 表单 -->
      <el-form :model="formData" ref="checkForm" :rules="rules">
        <el-form-item prop="chkState">
          <el-radio v-model="formData.chkState" :label="1">通过</el-radio>
          <el-radio v-model="formData.chkState" :label="2">拒绝</el-radio>
        </el-form-item>
        <el-form-item prop="chkRemarks">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入审核意见"
            v-model="formData.chkRemarks"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <!-- 按钮 -->
      <template v-slot:footer>
        <el-row type="flex" justify="end">
          <el-button plain @click="btnCancel">取消</el-button>
          <el-button type="primary" @click="btnOK">确定</el-button>
        </el-row>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
import eventBus from '@/EventBus/eventBus.js'
export default {
  props: {
    showCheckDialog: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      formData: {
        chkState: 1,
        chkRemarks: ''
      },
      rules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async btnOK() {
      this.$refs.checkForm.validate(async (valid) => {
        if (valid) {
          await choiceCheck({ ...this.formData, id: this.id })
          this.$message.success('操作成功')
          this.$emit('update:showCheckDialog', false)
          eventBus.$emit('updateCheckList') // 操作成功之后需要更新数据
        } else {
          this.$message.warning('请输入审核意见')
        }
      })
      // await this.$refs.checkForm.validate()
    },
    btnCancel() {
      // console.log(this.$refs.checkForm.resetFields)
      this.$refs.checkForm.resetFields()
      this.$emit('update:showCheckDialog', false)
    }
  }
}
</script>
